package cn.fsd.controller;

import cn.fsd.query.delivery.StockInOutQuery;
import cn.fsd.service.impl.StockInOutServiceImpl;
import cn.fsd.vo.ResultBean;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.util.StringUtils;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

// TODO: 2023/6/29 可能需要放到库房管理部分
@RestController
@RequestMapping("/stockInOutRecord")
public class StockInOutRecordController {

  @Autowired
  StockInOutServiceImpl stockInOutService;

  @PostMapping("/page")
  @ApiOperation(value = "分页查询指定库房商品的出入库记录")
  public ResultBean getInOutRecordByPage(@RequestBody StockInOutQuery query) {
    if(StringUtils.isEmpty(query.getWarehouse_id())){
      return ResultBean.error("库房id不能为空");
    }
    else if(query.getStartDate()!=null&&query.getEndDate()!=null){
      if(query.getStartDate().after(query.getEndDate())){
        return ResultBean.error("开始日期不能大于结束日期");
      }
    }
    return ResultBean.success(stockInOutService.getInOutRecordByPage(query));
  }

}
